<template>
  <div class="login-page">
  <van-nav-bar
  title="账号登录"
  left-arrow
  @click-left="$router.back()"
/>
 <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button  block type="primary" native-type="submit">提交</van-button>
     <router-link class="link" to="/register">还没有账号去注册</router-link>
  </div>
</van-form>
  </div>
</template>

<script>
import { login } from '@/api/user'
import { setToken } from '@/utils/storage'

export default {
  name: 'login-page',
  data () {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async  onSubmit (value) {
      console.log(value)
      const { body: { token } } = await login(value)
      console.log(token)
      setToken(token)
      this.$toast.success('登入成功了呢')
      this.$router.push('/')
    }

  }
}
</script>

<style lang="less" scoped>

.button{
  background-color: rgb(65, 177, 95);
}

.link {
  color: rgb(0, 0, 0);
  font-size: 13px;
  float: right;
  margin-right: 130px;
  margin-top: 10px;

}
</style>
